function [mat_X_FA, mat_Y_FA, mat_Y_FA_vol] = ...
    prepare_FA(dataX_normalize,gap_ret,time_lag);

mat_X_FA = [];
mat_Y_FA = [];
mat_Y_FA_vol = [];

for y = 0:4
    for q = 0:3
        year = 2007+y;
        quarter = 1+q;
        indLoc = intersect(find(dataX_normalize(:,2)==year),...
            find(dataX_normalize(:,3) == quarter));
        
        if ~isempty(indLoc)
            dataXyq = dataX_normalize(indLoc,4:end);
            sec_id = dataX_normalize(indLoc,1);
            
            switch time_lag
                case 1
                    if (quarter ~=4)
                        fromTime = sprintf('1/%d/%d',(quarter)*3+1, year);
                        toTime = sprintf('31/%d/%d',(quarter+1)*3, year);
                    else
                        fromTime = sprintf('1/1/%d',year+1);
                        toTime = sprintf('31/3/%d',year+1);
                    end
                    
                case 2
                    if (quarter <=2)
                        fromTime = sprintf('1/%d/%d',(quarter+1)*3+1, year);
                        toTime = sprintf('31/%d/%d',(quarter+2)*3, year);
                    else
                        fromTime = sprintf('1/%d/%d',(quarter-3)*3+1,year+1);
                        toTime = sprintf('31/%d/%d',(quarter-2)*3,year+1);
                    end
            end
            
            ret = [];
            for i = 1:size(sec_id,1)
                result = get_info_from_database('security', 'sec_id', sec_id(i) , ...
                    'from', fromTime, 'to', toTime);
                
                if (~isempty(result))
                    for j = 1:size(result,1)-gap_ret+1
                        profit = (result(j+gap_ret-1,6) - result(j,6))...
                            /result(j,6) * 100;
                        ret = [ret ; profit];
                    end
                    
                    mat_X_FA = [mat_X_FA ; dataXyq(i,:)];
                    
                    mat_Y_FA = [mat_Y_FA ; mean(ret)];
                    mat_Y_FA_vol = [mat_Y_FA_vol ; std(ret)];
                else
                    i; sec_id(i); year; quarter;
                end
            end
        end
    end
end

end